package com.ljfiction.book.Dialog;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

import com.ljfiction.book.R;

import java.util.Objects;

public class AuthorAidTishiDialog {
    private Dialog mDialog;
    private ImageView imageView;
    @SuppressLint("RtlHardcoded")
    public AuthorAidTishiDialog (Context context){
        mDialog = new Dialog(context, R.style.ActionSheetDialogStyle);
        View view = LayoutInflater.from(context).inflate(R.layout.author_first_tishi, null);
        imageView=view.findViewById(R.id.author_yinzhnag_dialog);
        //将布局设置给Dialog
        mDialog.setContentView(view);
        ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
        layoutParams.width = context.getResources().getDisplayMetrics().widthPixels;
        view.setLayoutParams(layoutParams);
        Objects.requireNonNull(mDialog.getWindow()).setGravity(Gravity.RIGHT|Gravity.BOTTOM);
        mDialog.getWindow().setWindowAnimations(R.style.ActionSheetDialogAnimation);
        mDialog.setCanceledOnTouchOutside(true);
        mDialog.setCancelable(true);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mDialog!=null){
                    mDialog.dismiss();
                }
            }
        });
        mDialog.show();
    }
}
